package org.keyuan.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.keyuan.dao.BookMsgFalshDao;
import org.keyuan.entity.BookMsgFalsh;
import org.keyuan.entity.BookType;
import org.keyuan.entity.util.ImgShowLocal;

public class BookMsgFalshDaoImpl extends DaoSupport<BookMsgFalsh> implements BookMsgFalshDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<BookMsgFalsh> getAdvertis(ImgShowLocal imgShowLocal,BookType booktype,Integer maxResults) {
		String hql="from BookMsgFalsh b where b.msgTitle is null and b.bookType=:booktype and b.isShowPage=:isShowPage and b.local=:local order by b.preference desc";
		Query query=this.getSession().createQuery(hql);
		query.setParameter("booktype", booktype);
		query.setParameter("local", imgShowLocal);
		query.setParameter("isShowPage", true);
		query.setFirstResult(0);
		query.setMaxResults(maxResults);
		return query.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<BookMsgFalsh> getBookMsgs(BookType bookType,Integer maxResults) {
		try{
		String hql="from BookMsgFalsh b where b.msgTitle is not null order by b.preference desc";
		Query query=this.getSession().createQuery(hql);
		//query.setParameter("booktype", bookType);
		//query.setParameter("isShowPage", true);
		query.setFirstResult(0);
		query.setMaxResults(maxResults);
		return query.list();
		}catch(HibernateException e){
			e.printStackTrace();
		}
		return null;
	}

}
